package net.roobook.cms.modules.admin.service;

import net.roobook.cms.common.service.CrudService;
import net.roobook.cms.modules.admin.dao.LabelMapper;
import net.roobook.cms.modules.admin.entity.Label;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author cos
 * @email 327878610@qq.com
 * @link https://roobook.net
 * @Description 标签Service
 * @date 2023/9/26 15:41
 **/
@Service
public class LabelService  extends CrudService<LabelMapper, Label> {
    @Autowired
    private LabelMapper labelMapper;
    public Map<String, List<Map<String,String>>> queryLabel() {
        Map<String,List<Map<String,String>>> map = new LinkedHashMap<String,List<Map<String,String>>>();
        //查询标签组
        List<String> groups = labelMapper.queryGroup();
        if(groups != null && groups.size()>0) {
            for (String group : groups) {
                List<Map<String,String>> list = labelMapper.queryLabelByGroup(group);
                map.put(group.toUpperCase(), list);
            }
        }
        return map;
    }

    @Transactional(readOnly = false)
    public int deleteByTagName(String tagName) {
        return labelMapper.deleteByTagName(tagName);
    }
}
